package com.liveneo.adapter.outinterface.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;

import com.liveneo.adapter.outinterface.web.platform.request.CaseInfoCancelRequest;

/**
  * @Description: 参数校验
  * @author liveneo-shuqw
  * @date 2016年10月26日 下午5:06:49
  * Copyright: Copyright (c) 2016 
  * Company: 北京朗泰
  * @version 3.0
  */
public class UtilValidateModel {

	/**
	  * @Title: validateModel
	  * @Description: 
	  * @param @param obj
	  * @param @return 设定文件
	  * @return String 返回类型
	  * @throws
	 */
	public static String validateModel(Object obj) { // 验证某一个对象
		StringBuffer buffer = new StringBuffer(64); // 用于存储验证后的错误信息
		Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
		Set<ConstraintViolation<Object>> constraintViolations = validator.validate(obj);// 验证某个对象,，其实也可以只验证其中的某一个属性的
		Iterator<ConstraintViolation<Object>> iter = constraintViolations.iterator();
		while (iter.hasNext()) {
			String message = iter.next().getMessage();
			buffer.append(message);
		}
		return buffer.toString();
	}
	
	public static void main(String[] args) {
		CaseInfoCancelRequest r = new CaseInfoCancelRequest();
		r.setCaseNo("222");
		r.setCaseType("5");
		r.setLossIds(new ArrayList<String>());
		System.out.println(validateModel(r));
	}
}
